<template>
  <!-- 公共驳回 -->
  <el-dialog
    title="驳回"
    :visible.sync="dialogVisible"
    width="30%"
    :before-close="handleClose"
  >
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
      <c-form-template>
        <el-col :span="24">
          <el-form-item label="驳回原因" :prop="field">
            <el-input
              type="textarea"
              class="wh"
              maxlength="100"
              show-word-limit
              v-model="ruleForm[field]"
              placeholder="请输入驳回原因"
            ></el-input>
          </el-form-item>
        </el-col>
      </c-form-template>
    </el-form>
    <span slot="footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  props: {
    field: {
      type: String,
      default: "rejection",
    },
  },
  data() {
    return {
      dialogVisible: false,
      ruleForm: {},
      rules: {},
    };
  },
  mounted() {
    this.rules[this.field] = [
      { required: true, message: "请输入驳回原因", trigger: "blur" },
    ];
  },
  methods: {
    handleSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.$confirm("是否确认此操作?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            const data = JSON.parse(JSON.stringify(this.ruleForm));
            this.$emit("change", data);
            this.handleClose();
          });
        }
      });
    },
    handleOpen(item = {}) {
      this.ruleForm = JSON.parse(JSON.stringify(item));
      this.dialogVisible = true;
    },
    handleClose() {
      this.ruleForm = {};
      this.$refs.ruleForm.resetFields();
      this.dialogVisible = false;
    },
  },
};
</script>
